//
//  UserSettings.m
//  iHealthEHR
//
//  Created by Joseph Ayo Akinyele on 5/17/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "UserSettings.h"

#define kGoogleHealth		@"googleEnvironment_setting"
#define vProduction			@"_production"
#define kEncryptedUpload	@"encryptedUpload_setting"
#define kActiveHospital1	@"activeHospital1_setting"
#define kActiveHospital2	@"activeHospital2_setting"
#define kActiveHospital3	@"activeHospital3_setting"
#define kHospitalName1		@"hospital1Name_setting"
#define kHospitalName2		@"hospital2Name_setting"
#define kHospitalName3		@"hospital3Name_setting"
#define kHospitalURL1		@"hospital1URL_setting"
#define kHospitalURL2		@"hospital1URL_setting"
#define kHospitalURL3		@"hospital1URL_setting"
#define kCacheRecord		@"cacheRecord_setting"
#define kCachePassphrase	@"passphrase_setting"

@implementation UserSettings

/* Determine if user wants to connect to google health production or sandbox.
   If production => YES, otherwise => NO
 */
+(BOOL) getGoogleHealthProdSetting
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	/* From iPhone beginner book --
	   Once we have a pointer to the standard user defaults, we use it just like an NSDictionary
	   Call objectForKey to get value, which returns NSString, NSDate or NSNumber.
	   While for scalars call: intForKey (int), floatforKey (float), or boolForKey: (BOOL). 
	 */
	
	NSString *value = [defaults objectForKey:kGoogleHealth];
	if ([value isEqualToString:vProduction]) {
		NSLog(@"Production mode for GH set.");
		return YES;
	}
	
	NSLog(@"Sandbox mode for GH set.");
	return NO;
}

+(BOOL) getEncryptedUpload
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];	
	return [defaults boolForKey:kEncryptedUpload];
}

+(NSString *) getActiveHospitalName
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

	if([defaults boolForKey:kActiveHospital1])
		return [defaults objectForKey:kHospitalName1];
	else if([defaults boolForKey:kActiveHospital2])
		return [defaults objectForKey:kHospitalName2];
	else if([defaults boolForKey:kActiveHospital3])
		return [defaults objectForKey:kHospitalName3];
	
	return nil;
}

+(NSString *) getActiveHospitalURL
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

	if([defaults boolForKey:kActiveHospital1])
		return [defaults objectForKey:kHospitalURL1];
	else if([defaults boolForKey:kActiveHospital2])
		return [defaults objectForKey:kHospitalURL2];
	else if([defaults boolForKey:kActiveHospital3])
		return [defaults objectForKey:kHospitalURL3];
		
	return nil;
}

+(BOOL) getCacheSetting
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];	
	return [defaults boolForKey:kCacheRecord];	
}

+(NSString *) getCachePassphrase
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];	
	return [defaults objectForKey:kCachePassphrase];
}

@end
